home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-desktop-9.10-i386-PL.iso / casper / filesystem.squashfs / usr / share / laptop-mode-tools / modules / cpufreq < prev    next >
Text File  |  2009-10-06  |  4KB  |  132 lines

  1. #! /bin/sh
  2. #
  3. # Laptop mode tools module to handle CPU frequency settings.
  4. #
  5.  
  6.  
  7.  
  8. # Set kernel setting, showing an error if this fails.
  9. # Parameter 1: sysctl/proc path
  10. # Parameter 2: the value
  11. set_sysctl() {
  12.     $LM_VERBOSE && echo "Executing: echo $2 > $1" >> $OUTPUT
  13.     if ! echo "$2" > "$1" ; then
  14.         echo "SETTING OF KERNEL PARAMETER FAILED: echo $2 \> $1"
  15.     fi
  16. }
  17.  
  18.  
  19. #
  20. # get_medium_value
  21. #
  22. #   Get the medium value from a list of numerical values.
  23. #   $1 = file containing the list of values
  24. #
  25. get_medium_value() {
  26.     cat "$1" | tr ' ' '\n' | sort -n | awk -v RS="" '{n=split($0,a); print a[int((n+1)/2)]}'
  27. }
  28.  
  29.  
  30. if [ x$CONTROL_CPU_FREQUENCY = x1 ] ; then
  31.     if [ $ON_AC -eq 1 ] ; then
  32.         if [ "$ACTIVATE" -eq 1 ] ; then
  33.             CPU_MAXFREQ="$LM_AC_CPU_MAXFREQ"
  34.             CPU_MINFREQ="$LM_AC_CPU_MINFREQ"
  35.             CPU_GOVERNOR="$LM_AC_CPU_GOVERNOR"
  36.             CPU_IGNORE_NICE_LOAD="$LM_AC_CPU_IGNORE_NICE_LOAD"
  37.         else
  38.             CPU_MAXFREQ="$NOLM_AC_CPU_MAXFREQ"
  39.             CPU_MINFREQ="$NOLM_AC_CPU_MINFREQ"
  40.             CPU_GOVERNOR="$NOLM_AC_CPU_GOVERNOR"
  41.             CPU_IGNORE_NICE_LOAD="$NOLM_AC_CPU_IGNORE_NICE_LOAD"
  42.         fi
  43.     else
  44.         CPU_MAXFREQ="$BATT_CPU_MAXFREQ"
  45.         CPU_MINFREQ="$BATT_CPU_MINFREQ"
  46.         CPU_GOVERNOR="$BATT_CPU_GOVERNOR"
  47.         CPU_IGNORE_NICE_LOAD="$BATT_CPU_IGNORE_NICE_LOAD"
  48.     fi
  49.     for THISCPU in /sys/devices/system/cpu/* ; do
  50.         if [ -e $THISCPU/cpufreq/cpuinfo_min_freq ]; then
  51.             THIS_CPU_MAXFREQ="$CPU_MAXFREQ"
  52.             THIS_CPU_MINFREQ="$CPU_MINFREQ"
  53.             THIS_CPU_GOVERNOR="$CPU_GOVERNOR"
  54.             THIS_CPU_IGNORE_NICE_LOAD="$CPU_IGNORE_NICE_LOAD"
  55.             
  56.             case "$CPU_MAXFREQ" in
  57.             "slowest")
  58.                 THIS_CPU_MAXFREQ=`cat $THISCPU/cpufreq/cpuinfo_min_freq`
  59.                 ;;
  60.             "medium")
  61.                 THIS_CPU_MAXFREQ=$(get_medium_value $THISCPU/cpufreq/scaling_available_frequencies)
  62.                 ;;
  63.             "fastest")
  64.                 THIS_CPU_MAXFREQ=`cat $THISCPU/cpufreq/cpuinfo_max_freq`
  65.                 ;;
  66.             esac
  67.             
  68.             case "$CPU_MINFREQ" in
  69.             "slowest")
  70.                 THIS_CPU_MINFREQ=`cat $THISCPU/cpufreq/cpuinfo_min_freq`
  71.                 ;;
  72.             "medium")
  73.                 THIS_CPU_MINFREQ=$(get_medium_value $THISCPU/cpufreq/scaling_available_frequencies)
  74.                 ;;
  75.             "fastest")
  76.                 THIS_CPU_MINFREQ=`cat $THISCPU/cpufreq/cpuinfo_max_freq`
  77.                 ;;
  78.             esac
  79.  
  80.             $LM_VERBOSE && echo "Setting CPU maximum frequency for cpu $THISCPU to $THIS_CPU_MAXFREQ." >> $OUTPUT
  81.             set_sysctl $THISCPU/cpufreq/scaling_max_freq $THIS_CPU_MAXFREQ
  82.             $LM_VERBOSE && echo "Setting CPU minimum frequency for cpu $THISCPU to $THIS_CPU_MINFREQ." >> $OUTPUT
  83.             set_sysctl $THISCPU/cpufreq/scaling_min_freq $THIS_CPU_MINFREQ
  84.             $LM_VERBOSE && echo "Setting CPU frequency governor for cpu $THISCPU to $THIS_CPU_GOVERNOR." >> $OUTPUT
  85.             /sbin/modprobe -q cpufreq_$THIS_CPU_GOVERNOR >> $OUTPUT 2>&1
  86.             set_sysctl $THISCPU/cpufreq/scaling_governor $THIS_CPU_GOVERNOR
  87.             if [ -f "$THISCPU/cpufreq/$THIS_CPU_GOVERNOR/ignore_nice_load" ] ; then
  88.                 $LM_VERBOSE && echo "Setting CPU ignore_nice_load for cpu $THISCPU to $THIS_CPU_IGNORE_NICE_LOAD." >> $OUTPUT
  89.                 set_sysctl $THISCPU/cpufreq/$THIS_CPU_GOVERNOR/ignore_nice_load $THIS_CPU_IGNORE_NICE_LOAD
  90.             else
  91.                 $LM_VERBOSE && echo "Not setting CPU ignore_nice_load for cpu $THISCPU." >> $OUTPUT
  92.                 $LM_VERBOSE && echo "File $THISCPU/cpufreq/$THIS_CPU_GOVERNOR/ignore_nice_load does not exist." >> $OUTPUT
  93.             fi
  94.         fi
  95.     done
  96. fi
  97.  
  98. if [ x$CONTROL_CPU_THROTTLING = x1 ] ; then
  99.     if [ $ON_AC -eq 1 ] ; then
  100.         if [ "$ACTIVATE" -eq 1 ] ; then
  101.             CPU_THROTTLING="$LM_AC_CPU_THROTTLING"
  102.         else
  103.             CPU_THROTTLING="$NOLM_AC_CPU_THROTTLING"
  104.         fi
  105.     else
  106.         CPU_THROTTLING="$BATT_CPU_THROTTLING"
  107.     fi
  108.     for THISCPU in /proc/acpi/processor/* ; do
  109.         if [ -e $THISCPU/throttling ]; then
  110.             NUM_LEVELS=`cat $THISCPU/throttling | grep "T[0123456789]*\:" | wc -l`
  111.             case "$CPU_THROTTLING" in
  112.             "minimum")
  113.                 THIS_CPU_THROTTLING=0
  114.                 ;;
  115.             "medium")
  116.                 # Divide but round up: that way, "medium" on a two-level system will
  117.                 # lead to full throttling -- which is 50% on my system, quite reasonable.
  118.                 THIS_CPU_THROTTLING=$(( ($NUM_LEVELS / 2 ) ))
  119.                 ;;
  120.             "maximum")
  121.                 THIS_CPU_THROTTLING=$(($NUM_LEVELS - 1))
  122.                 ;;
  123.             *)
  124.                 THIS_CPU_THROTTLING="$CPU_THROTTLING"
  125.             esac
  126.             
  127.             $LM_VERBOSE && echo "Setting throttling level for cpu $THISCPU to $THIS_CPU_THROTTLING." >> $OUTPUT
  128.             set_sysctl $THISCPU/throttling $THIS_CPU_THROTTLING
  129.         fi
  130.     done
  131. fi
  132.